From 4e7325c9e237bfa8626cdd7f7b7533328acb583d Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 10 Sep 2017 17:45:18 +0100 Subject: Fix crash for players out of the world. Fixes #4006 (#4007) --- src/Entities/Entity.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 33f5a6135..ba75f0443 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1662,7 +1662,9 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn) void cEntity::SetSwimState(cChunk & a_Chunk) { int RelY = FloorC(GetPosY() + 0.1); - if ((RelY < 0) || (RelY >= cChunkDef::Height - 1)) + int HeadRelY = CeilC(GetPosY() + GetHeight()) - 1; + ASSERT(RelY <= HeadRelY); + if ((RelY < 0) || (HeadRelY >= cChunkDef::Height)) { m_IsSwimming = false; m_IsSubmerged = false; @@ -1688,8 +1690,7 @@ void cEntity::SetSwimState(cChunk & a_Chunk) m_IsSwimming = IsBlockWater(BlockIn); // Check if the player is submerged: - int HeadHeight = CeilC(GetPosY() + GetHeight()) - 1; - VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, HeadHeight, RelZ, BlockIn)); + VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, HeadRelY, RelZ, BlockIn)); m_IsSubmerged = IsBlockWater(BlockIn); } -- cgit v1.2.3